/**
 * @filename UserAction.java
 * @package com.tianjian.dass.action.system[DASS]
 * @description 用户action
 * @author 胡正衛
 * @date 2012-6-6 上午10:04:50
 * @version v0.1
 */
package com.tianjian.oa.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.tianjian.common.BaseAction;
import com.tianjian.common.Criteria;
import com.tianjian.oa.system.pojos.UserInfo;
import com.tianjian.oa.system.services.UserService;

/**
 * @author 胡正衛
 */
public class UserAction extends BaseAction {

	private static final long serialVersionUID = -1760640666781976622L;

	@Autowired
	private UserService userService;

	private UserInfo userInfo;

	private Integer id;
	
	private String[] hospitals;

	public UserAction() {
		super("系统用户");
	}

	/* (non-Javadoc)
	 * @see com.tianjian.system.BaseAction#get()
	 */
	@Override
	public String get() {
		Criteria criteria = new Criteria();
		inversionCriteria(criteria);
		int total = userService.getCount(criteria);
		List<UserInfo> rows = null;
		try {
			rows = userService.getData(criteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.result.put("total", total);
		this.result.put("rows", rows);
		return JSON;
	}

	/* (non-Javadoc)
	 * @see com.tianjian.system.BaseAction#index()
	 */
	@Override
	public String index() {
		return SUCCESS;
	}

	/* (non-Javadoc)
	 * @see com.tianjian.system.BaseAction#view()
	 */
	@Override
	public String view() {
		return SUCCESS;
	}

	/**
	 * 添加用户
	 * @return
	 */
	@Override
	public String add() {
		int userid = userService.selectBh();
		userInfo.setId(userid);
		int rst = userService.add(userInfo);
		result.put("result", rst);
		return JSON;
	}

	/**
	 * 编辑用户资料
	 * @return
	 */
	@Override
	public String edit() {
		int rst = userService.edit(userInfo);
		result.put("result", rst);
		return JSON;
	}

	/**
	 * 停用或启用用户
	 * @return
	 */
	public String enable() {
		return JSON;
	}

	/**
	 * 删除用户
	 * @return
	 */
	@Override
	public String del() {
		int rst = userService.del(id);
		result.put("result", rst);
		return JSON;
	}

	/**
	 * 获取[userInfo]
	 * @return userInfo
	 */
	public UserInfo getUserInfo() {
		return userInfo;
	}

	/**
	 * 设置[userInfo]
	 * @param userInfo
	 */
	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String[] getHospitals() {
		return hospitals;
	}

	public void setHospitals(String[] hospitals) {
		this.hospitals = hospitals;
	}

}
